#!/usr/bin/python3
try:
    fixedL = [[0, 0] for row in range(50)]
    fixedL[0][0] = 1
    for i in range(49):
        fixedL[i + 1][1] += fixedL[i][0]
        fixedL[i + 1][0] += fixedL[i][1] + fixedL[i][0]

    T = int(input())
    for t in range(T):
        n = int(input()) + 1  # 加上0这种情况
        binaryL = []
        while n:  # 转二进制
            binaryL.append(n % 2)
            n = n // 2
        count = 0
        pre = -1
        while binaryL:
            temp = binaryL.pop()
            if temp == 1:
                count += fixedL[len(binaryL)][0] + fixedL[len(binaryL)][1]
            if (temp == 1 and pre == 1):  # 两个1相邻则结束
                break
            pre = temp
        print("Case #{}: {}".format(t + 1, count))
except ValueError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
